package ioperation;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:张熳
 * Date:2025-09-05
 * Time:15:49
 */

//写出你要归还的书名，遍历数组，如果找到与要归还的书名相同的书，且isborrowed的值是true，则将其改回false，并return

public class ReturnOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("归还图书📖");
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入要归还的图书书名📕：");
        String name = scanner.nextLine();

        int currentSize = bookList.getUsedSize();
        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBook(i);
            if (book.getName().equals(name)) {
                if (book.isIsborrowed()) {
                    book.setIsborrowed(false);
                    System.out.println("归还成功✨！");
                    return;
                }else {
                    System.out.println("这本书并没有被借出，无需归还📕！");
                    return;
                }
            }
        }
        System.out.println("没有你要归还的这本书！");
    }
}
